package com.echo.im.platform.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.echo.im.common.vo.message.PrivateMessageVO;
import com.echo.im.common.vo.message.SystemMessageVO;
import com.echo.im.platform.core.context.SessionContext;
import com.echo.im.platform.core.context.UserSession;
import com.echo.im.platform.core.dto.PullOfflineMessageDto;
import com.echo.im.platform.service.SystemMessageService;
import com.echo.im.repository.dao.entity.OfflineMessage;
import com.echo.im.repository.dao.entity.PrivateMessage;
import com.echo.im.repository.dao.entity.SystemMessage;
import com.echo.im.repository.offline.OfflineMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author: echo
 * @time: 2024-08-14
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SystemMessageServiceImpl implements SystemMessageService {

    private final OfflineMessageService<SystemMessage> systemMessageOfflineMessageService;

    @Override
    public List<SystemMessageVO> pullOfflineMessage(PullOfflineMessageDto dto) {
        UserSession session = SessionContext.getSession();
        List<SystemMessage> offLineMessages =
                systemMessageOfflineMessageService.fetchAndDeleteOfflineMessages(session.getUserId(), dto.getLastMsgId(), dto.getSize(), dto.getSessionUuid());
        List<SystemMessageVO> systemMessageVOList = BeanUtil.copyToList(offLineMessages, SystemMessageVO.class);
        return systemMessageVOList;
    }
}
